//
//  UIViewController+DF.m
//  换换圈
//
//  Created by 艾柯斯 on 14-11-7.
//  Copyright (c) 2014年 艾柯斯. All rights reserved.
//

#import "UIViewController+DF.h"
#import "ViewUtil.h"

@implementation UIViewController (DF)

- (void)addToRootViewController {
    UIViewController *topViewController = [ViewUtil topViewController];
    [topViewController addChildViewController:self];
    [topViewController.view addSubview:self.view];
}

- (void)dismiss {
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
}


+ (UIViewController *)topViewController
{
    UIViewController *topViewController = [self rootViewController];
    while (topViewController.presentedViewController) {
        topViewController = topViewController.presentedViewController;
    }
    return topViewController;
}


+ (UIViewController *)rootViewController
{
    UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    return rootViewController;
}


- (void)removeChildViewControllers {
    for (UIViewController* childViewController in self.childViewControllers) {
        [childViewController removeFromParentViewController];
    }
}




@end
